#include<iostream>
#include<queue>
#include<cstring>
using namespace std;

int mapGrid[200][200];
int fx[4] = {0, 0, -1, 1}; // 右、左、上、下
int fy[4] = {1, -1, 0, 0};

struct Point {
    int x;
    int y;
    int distance = -1; // 距离起点的距离
};

int main(){
    int x, y;
    while(cin >> x >> y){
        // 初始化网格
        memset(mapGrid, 0, sizeof(mapGrid));
        int a;
        Point target;
        // 声明队列在循环内，确保每个测试用例独立
        queue<Point> q;
        for(int i = 1; i <= x; i++){
            for(int j = 1; j <= y; j++){
                cin >> a;
                if(a == 1){
                    mapGrid[i][j] = 1; // 阻塞
                }
                if(a == 3){
                    Point start;
                    start.x = i;
                    start.y = j;
                    start.distance = 0;
                    q.push(start);
                    mapGrid[i][j] = 1; // 标记为已访问
                }
                if(a == 4){
                    target.x = i;
                    target.y = j;
                }
            }
        }
        int found = 0;
        while(!q.empty()){
            if(found) break;
            Point current = q.front();
            q.pop();
            for(int dir = 0; dir < 4; dir++){
                Point node;
                node.x = current.x + fx[dir];
                node.y = current.y + fy[dir];
                node.distance = current.distance + 1;
                // 添加边界条件检查
                if(node.x < 1 || node.x > x || node.y < 1 || node.y > y){
                    continue; // 超出边界，跳过
                }
                if(node.x == target.x && node.y == target.y){
                    target.distance = node.distance;
                    found = 1;
                    break;
                }
                if(!mapGrid[node.x][node.y]){
                    q.push(node);
                    mapGrid[node.x][node.y] = 1; // 标记为已访问
                }
            }
        }
        if(target.distance != -1){
            cout << target.distance << endl;
        }
        else{
            cout << "unreachable" << endl;
        }
    }
    return 0;
}
